<template>
    <div class="home">
        <!-- <h1>一级 home页面</h1> -->

        <el-container>
            <el-header style="height: 100px;">
                <div>
                    <img src="@/assets/logo.png" alt="">
                    <span>后台管理系统</span>
                </div>
                <div class="btn-outlogin">
                    <el-button type="danger" @click="outLogin">退出登录</el-button>
                </div>

            </el-header>
            <el-container>
                <el-aside :width="isCollapse ? '60px' : '250px'">
                    <div @click="isCollapse = !isCollapse" style="height: 15px;"></div>
                    <el-menu :router="true" default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
                        background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" :unique-opened="true" :collapse-transition="false" :collapse="isCollapse">
                        <el-submenu :index="item.id + ''" v-for="(item,index) in menuList" :key="item.id">
                            <template slot="title">
                                <i  style="margin-right: 10px;" :class="iconArr[index]"></i>
                                <span>{{ item.authName }}</span>
                            </template>
                            <el-menu-item :index="'/'+itemSub.path" v-for="itemSub in item.children" :key="itemSub.id">
                                <i class="el-icon-document-copy"></i>
                                <span slot="title">{{ itemSub.authName }}</span>
                            </el-menu-item>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
import { left_menu_req } from '@/api/menu.js';
export default {
    data() {
        return {
            menuList: [],
            iconArr:[
                'iconfont icon-shouce',
                'iconfont icon-banben',
                'iconfont icon-xinxi',
                'iconfont icon-quanxian',
                'iconfont icon-guanli',
            ],
            isCollapse:false,
        };
    },
    async mounted() {
        this.getMenuList();
    },
    methods: {
        async getMenuList() {
            const result = await left_menu_req({
                method: 'get',
                url: 'menus'
            })
            console.log(result);
            if (result.meta.status == 200) {
                this.menuList = result.data;
            }
        },
        outLogin() {
            window.sessionStorage.removeItem('token');
            this.$router.push('/login');
        }
        ,
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        }
    }
}
</script>

<style lang="scss" scoped>
.home {
    height: 100%;

    .el-container {
        height: 100%;

        .el-header {
            background-color: #81abe3;
            color: #333;
            text-align: center;
            line-height: 100px;
            display: flex;
            justify-content: space-between;

            div {
                img {
                    width: 50px;
                    height: 50px;
                }

                span {
                    font-size: 25px;
                    font-family: '幼圆';
                }
            }

            .btn-outlogin {
                height: 35px;
            }
        }

        .el-container {
            .el-aside {
                background-color: #8fd696;
                color: #333;
                text-align: center;
                line-height: 200px;

                .el-menu {
                    height: 100%;
                    .el-submenu {
                        .el-menu-item {
                            margin-left: 30px;
                        }
                    }
                }
            }

            .el-main {
                background-color: #f22d29b8;
                color: #333;
                text-align: center;
                line-height: 160px;
            }
        }

    }

}
</style>